package com.qcby.controller;

import com.qcby.entity.PageResult;
import com.qcby.entity.Result;
import com.qcby.entity.Student;
import com.qcby.service.DeepSeekService;
import com.qcby.service.ExamService;
import com.qcby.service.MessageService;
import com.qcby.service.StudentService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Api(tags = "学生接口")
@Controller
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private MessageService messageService;
    @Autowired
    private ExamService examService;
    @Autowired
    private DeepSeekService deepSeekService;
    @Autowired
    private StudentService studentService;


    @ApiModelProperty(value = "AI分析接口")
    @PostMapping("/AIAnalyze")
    @ResponseBody
    public Result AIAnalyze(Student student){
        System.out.println(student);
        return Result.success(studentService.AnalyzeAllStudentInfo(student));
    }

    @ApiModelProperty(value = "登录接口")
    @PostMapping("/login")
    @ResponseBody
    public Result login(Student student, HttpServletRequest request) {
        System.out.println(student);
        return studentService.login(student,request);
    }
    @ApiModelProperty(value = "学生全部信息")
    @PostMapping("/list")
    @ResponseBody
    public Result list(Student student) {
        System.out.println(student);
        PageResult<Student> p =  studentService.list(student);
        return Result.success(p);
    }
    @ApiModelProperty(value = "学生全部信息")
    @PostMapping("/list1")
    @ResponseBody
    public Result list1(Student student) {
        System.out.println(student);
        PageResult<Student> p =  studentService.list1(student);
        return Result.success(p);
    }
    @ApiModelProperty(value = "添加学生接口")
    @PostMapping("/addstudent")
    @ResponseBody
    public Result addstudent(Student student) {
        studentService.addstudent(student);
        return Result.success();
    }
    @ApiModelProperty(value = "删除学生接口")
    @PostMapping("/deletestudent")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "学生id")
    })
    @ResponseBody
    public Result deletestudent(Integer id) {
        studentService.deletestudent(id);
        return Result.success();
    }
    @ApiModelProperty(value = "修改学生接口")
    @PostMapping("/updatestudent")
    @ResponseBody
    public Result updatestudent(Student student) {
        studentService.updatestudent(student);
        return Result.success();
    }
    @ApiModelProperty(value = "AI分析学生所有的信息")
    @PostMapping("/AnalyzeAllStudentInfo")
    @ResponseBody
    public Result AnalyzeAllStudentInfo(Student student) {
        System.out.println(student);
        Map<String, String> resMap = studentService.AnalyzeAllStudentInfo(student);
        return Result.success(resMap);
    }
    @ApiModelProperty(value = "通过学生姓名查找信息")
    @PostMapping("/findMessage")
    @ResponseBody
    public Result findMessage(Student student) {
        return Result.success(studentService.findMessage(student));
    }
    @ApiModelProperty(value = "通过学生是否有重复信息")
    @PostMapping("/findRepeatMessage")
    @ResponseBody
    public Result findRepeatMessage(Student student) {
        Integer res = studentService.findRepeatMessage(student);
        if (res == 0) {
            return Result.success();
        }else{
            return Result.error();
        }
    }
    @ApiModelProperty(value = "退出学生")
    @GetMapping("/logout")
    public Result logout(HttpServletRequest request) {
        request.getSession().removeAttribute("student");
        return Result.success();
    }
}
